package com.jr.dao.impl;

import com.jr.dao.InvoicingRecordDao;
import com.jr.entity.InvoicingRecord;
import com.jr.util.DAO;

import java.util.List;

/**
 * @program:(invoice)
 * @author:Mr.Jin
 * @Date:(2023/2/25)
 */
public class InvoicingRecordDaoImpl extends DAO<InvoicingRecord> implements InvoicingRecordDao {
    @Override
    public int addInvoice(InvoicingRecord invoicingRecord) throws Exception {
        String sql="INSERT INTO invoicing_record (amount,enterprise_id,creator_id,category,type,title,address,email,uplink_address,status) VALUES (?,?,?,?,?,?,?,?,?,?)";
        return update(sql, invoicingRecord.getAmount(), invoicingRecord.getEnterpriseId(), invoicingRecord.getCreatorId(), invoicingRecord.getCategory(), invoicingRecord.getType(),invoicingRecord.getTitle(), invoicingRecord.getAddress(), invoicingRecord.getEmail(), invoicingRecord.getUplinkAddress(),invoicingRecord.getStatus());
    }

    @Override
    public int deleteInvoice() throws Exception {
        String sql = "UPDATE invoicing_record SET exist = '0' WHERE exist = 1";
        return update(sql);
    }

    /**
     * 主页展示发票详情信息
     * @param enterpriseId
     * @return
     * @throws Exception
     */
    @Override
    public List<InvoicingRecord> allInvoiceMessage(Integer enterpriseId) throws Exception {
        String sql = "SELECT id,create_time AS createTime,title,amount,uplink_address As uplinkAddress ,status FROM invoicing_record WHERE enterprise_id = ?";
        return getForList(sql,enterpriseId);
    }



    /**
     * 根据发票id进行退票
     * @param invoiceId
     * @return
     * @throws Exception
     */
    @Override
    public int refundTicket(Integer invoiceId) throws Exception {
        String sql = "UPDATE invoicing_record SET `status`='已作废' WHERE id=?";
        return update(sql,invoiceId);
    }

}
